Ensure that the prefix is valid UTF-8. (#419568, Nickolay V. Shmyrev)
authorMatthias Clasen <mclasen@redhat.com>
Mon, 19 Mar 2007 04:27:45 +0000 (04:27 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Mon, 19 Mar 2007 04:27:45 +0000 (04:27 +0000)
2007-03-18  Matthias Clasen <mclasen@redhat.com>

        * gtk/gtkentrycompletion.c (gtk_entry_completion_compute_prefix):
        Ensure that the prefix is valid UTF-8.  (#419568, Nickolay V. Shmyrev)

svn path=/trunk/; revision=17543

ChangeLog
gtk/gtkentrycompletion.c

index 2ec7c88b02bc423a13b15b037eb156fd99c33dab..02e0bd76f167db0c2e0641148bd10b436bbc749a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2007-03-18  Matthias Clasen <mclasen@redhat.com> 
+
+       * gtk/gtkentrycompletion.c (gtk_entry_completion_compute_prefix):
+       Ensure that the prefix is valid UTF-8.  (#419568, Nickolay V. Shmyrev)
+
 2007-03-18  Matthias Clasen <mclasen@redhat.com> 
 
        * modules/input/gtkimcontextmultipress.[hc]:
index d4c51b4f494f9b97aa79c5004c33d1012539420b..d8bc08a06ae48969aa767aaffe8917b0820679d0 100644 (file)
@@ -1500,7 +1500,7 @@ gtk_entry_completion_compute_prefix (GtkEntryCompletion *completion)
          else
            {
              gchar *p = prefix;
-             const gchar *q = text;
+             gchar *q = text;
              
              while (*p && *p == *q)
                {
@@ -1509,6 +1509,19 @@ gtk_entry_completion_compute_prefix (GtkEntryCompletion *completion)
                }
              
              *p = '\0';
+              
+              if (p > prefix)
+                {
+                  /* strip a partial multibyte character */
+                  q = g_utf8_find_prev_char (prefix, p);
+                  switch (g_utf8_get_char_validated (q, p - q))
+                    {
+                    case (gunichar)-2:
+                    case (gunichar)-1:
+                      *q = 0;
+                    default: ;
+                    }
+                }
            }
        }